package com.namecard.namecardapi.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author wzx
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
public class ResponseVO<T> {

    private String status;
    private Integer code;
    private String info;
    private T data;

    public ResponseVO(String statusByCode, int code, String msgByCode) {
        this.status=statusByCode;
        this.code=code;
        this.info=msgByCode;
    }

    /**
     *成功的响应
     **/
    public static <T> ResponseVO<T> getSuccessResponseVo(T data){
        return new ResponseVO<>("success", 200, "请求成功", data);
    }
    /**
     *失败的响应
     **/
    public static <T> ResponseVO<T> getErrorResponseVo(T data){
        return new ResponseVO<>("error", 500, "请求失败", data);
    }
    /**
     *失败消息响应
     **/
    public static <T> ResponseVO<T> getErrorResponseMsg(String data){
        return new ResponseVO<>("error", 500, data, null);
    }
}
